define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'assignsuperiors/index' + location.search,

                    table: 'user_details',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'role_text', title: __('Role'), searchList: {"agent":__('role Agent'),"room":__('role Room')}, formatter: Table.api.formatter.normal},
                       {field: 'img', title: __('Img'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'phone', title: __('Phone'), operate: 'LIKE'},
                        {field: 'age', title: __('Age')},
                        {field: 'addr', title: __('addr')},
                        {
                            field: 'operate', title: __('Operate'), table: table, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'choose',
                                    text: '选择',
                                    title: '选择',
                                    classname: 'btn btn-xs btn-info btn-click',
                                    icon: 'fa fa-check-circle',
                                    click: function (index, row) {
                                        console.log('choose row', row);
                                        // 回传数据给Fast.api.open的callback,很重要
                                        Fast.api.close({row:row});
                                    }
                                }
                            ],
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
